package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserInfoApiImpl implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    //根据id查找用户的信息
    @Override
    public UserInfo findById(Long id) {
        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }

    @Override
    public Page<UserInfo> findBlackList(Integer pageNum, Integer pagesize, Long userId) {
        //创建一个Page对象
        Page<UserInfo> page = new Page<>(pageNum,pagesize);
        //根据用户id查询当前的用户的黑名单列表, 自定义方法使用mybatis-plus分页要求： 1. 方法的返回值必须是page，2.方法的形参必须要接受Page
        userInfoMapper.findBlackList(page,userId);

        return page;
    }

    @Override
    public Page<UserInfo> findByPage(Integer page, Integer pagesize) {
        //设置当前页与页面大小
        Page<UserInfo> pageInfo = new Page<>(page,pagesize);
        userInfoMapper.selectPage(pageInfo, null);
        return pageInfo;
    }

    @Override
    public List<UserInfo> findByIds(List<Long> userIdList) {
        return userInfoMapper.selectBatchIds(userIdList);
    }
}
